package com.dy.dygang;
import java.io.IOException;
import java.net.URLEncoder;
import org.jsoup.Connection.Response;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class DouBan {

	public static void serarch(String name) throws IOException {
		Response res = Jsoup.connect("http://movie.douban.com/j/subject_suggest?q="+URLEncoder.encode(name,"utf-8"))
				.header("Accept", "*/*")
				.header("Accept-Encoding", "gzip, deflate")
				.header("Accept-Language","zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
				.header("Content-Type", "application/json;charset=UTF-8").ignoreContentType(true).execute();
		JSONArray result = new JSONArray(res.body());
		JSONObject jsonObject = result.getJSONObject(0);
		String url = jsonObject.getString("url");
		url = url.replaceAll("https://", "http://");
		
		Response moveRes = Jsoup.connect(url)
				.header("Accept", "*/*")
				.header("Accept-Encoding", "gzip, deflate")
				.header("Accept-Language","zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
				.header("Content-Type", "application/json;charset=UTF-8").ignoreContentType(true).execute();
		
		//电影信息
		Element moveInfo = Jsoup.parse(moveRes.body()).getElementById("info");
		Elements spans = moveInfo.select("span");
		System.out.println(spans);
		int index = 0;
		DouBanView douBanView = new DouBanView();
		for (Element span : spans) {
			if(index==0) {
				douBanView.daoyan = span.select("a").get(0).text();
			}else if(index==3) {
				
			}
			index++;
		}
	}
	public static void main(String[] args) throws IOException {
		serarch("我的爸爸是森林之王");
	}
}
